<SCRIPT LANGUAGE="JavaScript">  

    function swap(temp)
    {
        for(i=0;i<document.getElementById('jumlah').value;i++)
        {
            document.getElementById('check'+i).checked = temp.checked;
        }
    }

    function check_all()
    {
        for(i=0;i<document.getElementById('jumlah').value;i++)
        {
            document.getElementById('check'+i).checked = true;
        }
        document.getElementById('checkall').checked = true;
    }

    function uncheck_all()
    {
        for(i=0;i<document.getElementById('jumlah').value;i++)
        {
            document.getElementById('check'+i).checked = false;
        }
        document.getElementById('checkall').checked = false;
    }    
    
    function validation()
    {
        var pass = false;
        for(i=0;i<document.getElementById('jumlah').value;i++)
        {
            if( document.getElementById('check'+i).checked == true )
            {
                pass = true;
            }
        
        }
        
        if(pass)
        { return confirm('Are you sure ?'); }
        else
        { alert('You must choose at least one of your clipboard to be deleted'); return false; }
        
    }

    var xx = 100;
    var yy = 100;
    var tx = 0;
    var ty = 0;
    var dx = 0;
    var dy = 0;
    var klik = 0;
    
    function make_slip(event)
    {  
        if(event)
        {
            xx=event.clientX;
            yy=event.clientY;
        }
        else
        {
            xx=100;
            yy=100;
        }
        klik=0;
        
        var temp = document.getElementById('slip');
        temp.style.position = 'absolute';
        temp.style.borderTop = '4px solid #ddd';
        temp.style.borderLeft = '4px solid #ddd';
        temp.style.borderBottom = '4px solid #aaa';
        temp.style.borderRight = '4px solid #aaa';
        temp.style.top = yy+'px';
        temp.style.left = xx+'px';
        temp.style.width = 'auto';
        temp.style.height = 'auto';
        temp.style.backgroundColor = 'white';
    }
    
    function close_slip()
    {  
        document.getElementById('slip').innerHTML = '';
        document.getElementById('slip').style.border = 'none';
    }
    
    function tekan(event)
    {
        klik = 1;
        tx=event.clientX;
        ty=event.clientY;
    }
    
    function gerak(event)
    {
        if(klik==1)
        {
            dx=event.clientX-tx;
            dy=event.clientY-ty;
            
            xx = xx + dx;
            yy = yy + dy;
            
            document.getElementById('slip').style.top = yy+'px';
            document.getElementById('slip').style.left = xx+'px';      
            
            tx=event.clientX;
            ty=event.clientY;
        }
    }    
    
    function lepas()
    {
        klik=0;
    }

    function open_win2(id)
    {
        window.open('../jobs/view/'+id,"_blank","toolbar=no, location=yes, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=yes, top=100, left=100, width=930, height=600");
    }
    
    
    function open_win(id)
    {
        window.open('../employers/view/'+id,"_blank","toolbar=no, location=yes, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=yes, top=100, left=100, width=930, height=600");
    }
    
</SCRIPT>

<?php
    
   echo "<div class='form'>"; 
   echo "<h2> Saved Jobs </h2>";
   echo "<hr color='#2A7EF7'>";   
   echo ":. This page records job(s) that saved into your clipboard. <span class='info'> ( Max : 10 records ) </span>";
   if(!empty($clipboards))
   {
        echo $this->element('myfunction');
        
        echo $form->create('Clipboard',array('controller'=>'clipboards','action'=>'my_clipboards','onsubmit'=>'return validation();'));
        echo "<table class='saved_jobs' cellspacing=0 cellpadding=0>";
            echo "<input type='hidden' id='jumlah' name='data[jumlah]' value=".count($clipboards).">";
            echo "<tr> <th width='60px'><input type='checkbox' id='checkall' onClick='swap(this)'></th> <th width='100px'>Clip Date</th><th width='100px'>Post Date</th><th width='250px'>Position</th><th width='180px'>Company</th><th width='100px'>Job Status</th><th width='100px'>Action</th> </tr>";
            for($i=0;$i<10;$i++)
            {
                if(!empty($clipboards[$i]))     
                {
                    echo "<tr>";
                        echo "<td><input type='checkbox' name='data[check".$i."]' id='check".$i."' value=".$clipboards[$i]['clipboards']['id']."></td>";
                        echo "<td>".mydate($clipboards[$i]['clipboards']['created'])."</td>";
                        echo "<td width='100px'>".mydate($clipboards[$i]['jobs']['created'])."</td>";
                        //echo "<td>".$html->link($clipboards[$i]['jobs']['position'],array('controller'=>'jobs','action'=>'view',$clipboards[$i]['jobs']['id']),array('class'=>'blue'))."&nbsp ";
                        echo "<td> <a href='javascript:open_win2(".$clipboards[$i]['jobs']['id'].")' class='sky'>".$clipboards[$i]['jobs']['position']."</a> &nbsp"; 
                        echo $ajax->link("<img src='../img/hint.gif'>",
                                        array('controller'=>'jobs','action'=>'detail',$clipboards[$i]['jobs']['id']),
                                        array('update'=>'slip','complete'=>"make_slip(event);"),
                                        null,false
                                        
                                     ); 
                        echo "</td>";
                        //echo "<td>".$html->link($clipboards[$i]['employers']['company_name'],array('controller'=>'employers','action'=>'view',$clipboards[$i]['employers']['id']))."</td>";
                        echo "<td><a href='javascript:open_win(".$clipboards[$i]['employers']['id'].")'>".$clipboards[$i]['employers']['company_name']."</a></td>";
                        
                        if($clipboards[$i]['jobs']['end_date']>=date("Y-m-d"))
                        { echo "<td> <span class='yes'>Open</span> </td>"; }
                        else
                        { echo "<td> <span class='no'>Closed</span> </td>"; }
                        
                        echo "<td> ".$html->link('[ Apply Now ]',array('controller'=>'applicants','action'=>'apply',$clipboards[$i]['jobs']['id']))." </td>";
                    echo "</tr>";
                }
                else
                {
                    echo "<tr><td colspan=7></td></tr>";    
                }
            
            }
            echo "<tr class='end'><td class='end' colspan=7><input type='submit' value='Delete'>&nbsp&nbsp&nbsp <a href='Javascript:check_all();'>[ Select All ]</a>&nbsp&nbsp&nbsp <a href='Javascript:uncheck_all();'>[ Unselect All ]</a> </td></tr>";
        echo "</table>";
        echo "</form>";
        
  }
  else
  { 
    echo "<br><span class='red'> &nbsp &nbsp You don't have any saved jobs </span>"; 
  }
  
  echo "</div>";
  echo "<div id='slip'></div>";
?>